home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: C beginner needs your help ASAP
- Date: 18 Feb 1996 22:23 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <18FEB199622233346@erich.triumf.ca>
- References: <4g862f$p0b@risky.ecs.umass.edu> <4g8ahd$p8b@spectator.cris.com>
- NNTP-Posting-Host: ftp.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <4g8ahd$p8b@spectator.cris.com>, aubrey@concentric.net (Aubrey Harrison) writes...
- >In article <4g862f$p0b@risky.ecs.umass.edu>, sebag@ecs.umass.edu says...
- >>
- >>I am a new C programmmer who desperately needs help.
- >>I have been digging in the manuals for a way to do this but have still
- >>come out empty handed. Here is the problem: I want to open files in a while
- >>loop with different filenames. data0,data1,data2,data3, .. data1000 , ...
- >>I need to increment an integer each time around then convert it to a string
- >>and then somehow use strcat to combine the "data" with the integer string.
- >>After that use fopen(filename, "a");
- > for(i=0; i<10; i++)
- > {
- > sprintf(buf,"%d",i);
- > strcpy( filename,"data");
- > strcat( filename, buf );
- > strcat( filename, ".ext");
- > printf( "%s\n", filename);
- > }
-
- This is a little easier, I think:
-
- FILE * fp;
- char filename[143];
- int i;
- for(i = 0, i < 10; i++)
- {
- sprintf(filename, "data%d.ext", i);
- if((fp = fopen(filename, "r")) == NULL)
- /* report error or .... */
- /* do stuff */
- }
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
-
-
-
-
-
-
-